package com.gis.visualization.controller;


import com.gis.visualization.config.result.R;
import com.gis.visualization.entity.vo.FigureLocationVo;
import com.gis.visualization.service.FigureLocationService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 人物地点表 前端控制器
 * </p>
 *
 * @author hqz
 * @since 2021-02-23
 */
@RestController
@RequestMapping("/visualization/figurelocation")
//@CrossOrigin
public class FigureLocationController {
    @Autowired
    private FigureLocationService locationService;

    @ApiOperation("添加人物地点信息")
    @PostMapping("addFigureLocation")
    public R addFigureLocation(@RequestBody FigureLocationVo figureLocationVo) {
        String locationId = locationService.addFigureLocation(figureLocationVo);
        return R.ok().data("locationId", locationId).message("地点信息添加成功");
    }

    @ApiOperation("查询人物地点信息")
    @GetMapping("getFigureLocation/{figureId}")
    public R getFigureLocation(@PathVariable String figureId) {
        List<FigureLocationVo> figureLocationList = locationService.getFigureLocation(figureId);
        return R.ok().data("figureLocationList", figureLocationList);
    }

    @ApiOperation("修改人物地点信息")
    @PostMapping("updateFigureLocation")
    public R updateFigureLocation(@RequestBody FigureLocationVo figureLocationVo) {
        locationService.updateFigureLocation(figureLocationVo);
        return R.ok().message("修改人物地点信息成功");
    }

    @ApiOperation("删除人物地点信息")
    @DeleteMapping("deleteFigureLocation/{locationId}")
    public R deleteFigureLocation(@PathVariable String locationId) {
        locationService.deleteFigureLocation(locationId);
        return R.ok().message("删除人物地点信息成功");
    }

    @ApiOperation("分页查询人物地点")
    @PostMapping("getPageFigureLocation/{figureId}/{current}/{limit}")
    public R getPageFigureLocation(@PathVariable String figureId,
                                   @PathVariable long current,
                                   @PathVariable long limit) {
        Map<String, Object> pageLocation = locationService.getPageFigureLocation(figureId,current, limit);
        return R.ok().data("pageLocation", pageLocation);
    }

    @ApiOperation("根据人物id删除地点")
    @DeleteMapping("deleteLocationByFigureId/{figureId}")
    public R deleteLocationByFigureId(@PathVariable String figureId) {
        locationService.deleteLocationByFigureId(figureId);
        return R.ok().message("删除人物地点信息成功");
    }

    @ApiOperation("根据地点id删除地点")
    @DeleteMapping("deleteSelectLocations")
    public R deleteSelectLocations(@RequestBody List<String> locationIds) {
        locationService.deleteSelectLocations(locationIds);
        return R.ok().message("删除人物地点信息成功");
    }
}

